﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:Controls="clr-namespace:Elysium.Theme.Controls"
                    xmlns:Root="clr-namespace:Elysium.Theme">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="/Elysium.Theme;component/Themes/SharedResources.xaml"/>
    </ResourceDictionary.MergedDictionaries>

    <ControlTemplate x:Key="HorizontalProgressBarTemplate" TargetType="{x:Type Controls:ProgressBar}">

        <Grid x:Name="PART_Track"
              Background="{TemplateBinding Background}"
              ClipToBounds="True"
              SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
            <Rectangle x:Name="PART_Indicator"
                       Fill="{StaticResource Accent}"
                       StrokeThickness="0"
                       HorizontalAlignment="Stretch"
                       VerticalAlignment="Stretch">
                <Rectangle.RenderTransform>
                    <ScaleTransform ScaleX="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Percent}"/>
                </Rectangle.RenderTransform>
            </Rectangle>
            <Canvas x:Name="PART_LoadingBar"
                    Background="{StaticResource Background}"
                    Visibility="Collapsed">
                <Ellipse Fill="{StaticResource Accent}"
                         StrokeThickness="0"
                         Canvas.Left="{TemplateBinding Root:Parameters.ProgressBarLoadingElementStartPosition}" Canvas.Top="0"
                         Width="{TemplateBinding Root:Parameters.ProgressBarLoadingElementSize}" Height="{TemplateBinding Root:Parameters.ProgressBarLoadingElementSize}"/>
                <Ellipse Fill="{StaticResource Accent}"
                         StrokeThickness="0"
                         Canvas.Left="{TemplateBinding Root:Parameters.ProgressBarLoadingElementStartPosition}" Canvas.Top="0"
                         Width="{TemplateBinding Root:Parameters.ProgressBarLoadingElementSize}" Height="{TemplateBinding Root:Parameters.ProgressBarLoadingElementSize}"/>
                <Ellipse Fill="{StaticResource Accent}"
                         StrokeThickness="0"
                         Canvas.Left="{TemplateBinding Root:Parameters.ProgressBarLoadingElementStartPosition}" Canvas.Top="0"
                         Width="{TemplateBinding Root:Parameters.ProgressBarLoadingElementSize}" Height="{TemplateBinding Root:Parameters.ProgressBarLoadingElementSize}"/>
                <Ellipse Fill="{StaticResource Accent}"
                         StrokeThickness="0"
                         Canvas.Left="{TemplateBinding Root:Parameters.ProgressBarLoadingElementStartPosition}" Canvas.Top="0"
                         Width="{TemplateBinding Root:Parameters.ProgressBarLoadingElementSize}" Height="{TemplateBinding Root:Parameters.ProgressBarLoadingElementSize}"/>
                <Ellipse Fill="{StaticResource Accent}"
                         StrokeThickness="0"
                         Canvas.Left="{TemplateBinding Root:Parameters.ProgressBarLoadingElementStartPosition}" Canvas.Top="0"
                         Width="{TemplateBinding Root:Parameters.ProgressBarLoadingElementSize}" Height="{TemplateBinding Root:Parameters.ProgressBarLoadingElementSize}"/>
            </Canvas>
        </Grid>

        <ControlTemplate.Triggers>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsIndeterminate" Value="True"/>
                    <Condition Property="IsEnabled" Value="True"/>
                </MultiTrigger.Conditions>
                <MultiTrigger.Setters>
                    <Setter TargetName="PART_Indicator" Property="RenderTransform">
                        <Setter.Value>
                            <ScaleTransform ScaleX="0.3"/>
                        </Setter.Value>
                    </Setter>
                </MultiTrigger.Setters>
            </MultiTrigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsIndeterminate" Value="{x:Null}"/>
                    <Condition Property="IsEnabled" Value="True"/>
                </MultiTrigger.Conditions>
                <MultiTrigger.Setters>
                    <Setter TargetName="PART_Indicator" Property="Visibility" Value="Collapsed"/>
                    <Setter TargetName="PART_LoadingBar" Property="Visibility" Value="Visible"/>
                </MultiTrigger.Setters>
            </MultiTrigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <ControlTemplate x:Key="VerticalProgressBarTemplate" TargetType="{x:Type Controls:ProgressBar}">

        <Grid x:Name="PART_Track"
              Background="{TemplateBinding Background}"
              ClipToBounds="True"
              SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
            <Rectangle x:Name="PART_Indicator"
                       Fill="{StaticResource Accent}"
                       StrokeThickness="0"
                       HorizontalAlignment="Stretch"
                       VerticalAlignment="Stretch">
                <Rectangle.RenderTransform>
                    <ScaleTransform ScaleY="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Percent}"/>
                </Rectangle.RenderTransform>
            </Rectangle>
            <Canvas x:Name="PART_LoadingBar"
                    Background="{StaticResource Background}"
                    Visibility="Collapsed">
                <Ellipse Fill="{StaticResource Accent}"
                         StrokeThickness="0"
                         Canvas.Left="0" Canvas.Top="{TemplateBinding Root:Parameters.ProgressBarLoadingElementStartPosition}"
                         Width="{TemplateBinding Root:Parameters.ProgressBarLoadingElementSize}" Height="{TemplateBinding Root:Parameters.ProgressBarLoadingElementSize}"/>
                <Ellipse Fill="{StaticResource Accent}"
                         StrokeThickness="0"
                         Canvas.Left="0" Canvas.Top="{TemplateBinding Root:Parameters.ProgressBarLoadingElementStartPosition}"
                         Width="{TemplateBinding Root:Parameters.ProgressBarLoadingElementSize}" Height="{TemplateBinding Root:Parameters.ProgressBarLoadingElementSize}"/>
                <Ellipse Fill="{StaticResource Accent}"
                         StrokeThickness="0"
                         Canvas.Left="0" Canvas.Top="{TemplateBinding Root:Parameters.ProgressBarLoadingElementStartPosition}"
                         Width="{TemplateBinding Root:Parameters.ProgressBarLoadingElementSize}" Height="{TemplateBinding Root:Parameters.ProgressBarLoadingElementSize}"/>
                <Ellipse Fill="{StaticResource Accent}"
                         StrokeThickness="0"
                         Canvas.Left="0" Canvas.Top="{TemplateBinding Root:Parameters.ProgressBarLoadingElementStartPosition}"
                         Width="{TemplateBinding Root:Parameters.ProgressBarLoadingElementSize}" Height="{TemplateBinding Root:Parameters.ProgressBarLoadingElementSize}"/>
                <Ellipse Fill="{StaticResource Accent}"
                         StrokeThickness="0"
                         Canvas.Left="0" Canvas.Top="{TemplateBinding Root:Parameters.ProgressBarLoadingElementStartPosition}"
                         Width="{TemplateBinding Root:Parameters.ProgressBarLoadingElementSize}" Height="{TemplateBinding Root:Parameters.ProgressBarLoadingElementSize}"/>
            </Canvas>
        </Grid>

        <ControlTemplate.Triggers>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsIndeterminate" Value="True"/>
                    <Condition Property="IsEnabled" Value="True"/>
                </MultiTrigger.Conditions>
                <MultiTrigger.Setters>
                    <Setter TargetName="PART_Indicator" Property="RenderTransform">
                        <Setter.Value>
                            <ScaleTransform ScaleY="0.3"/>
                        </Setter.Value>
                    </Setter>
                </MultiTrigger.Setters>
            </MultiTrigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsIndeterminate" Value="{x:Null}"/>
                    <Condition Property="IsEnabled" Value="True"/>
                </MultiTrigger.Conditions>
                <MultiTrigger.Setters>
                    <Setter TargetName="PART_Indicator" Property="Visibility" Value="Collapsed"/>
                    <Setter TargetName="PART_LoadingBar" Property="Visibility" Value="Visible"/>
                </MultiTrigger.Setters>
            </MultiTrigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <Style x:Key="{x:Type Controls:ProgressBar}" TargetType="{x:Type Controls:ProgressBar}">

        <Setter Property="Background" Value="{StaticResource ForegroundHighlight}"/>
        <Setter Property="BorderBrush" Value="{StaticResource ForegroundMiddlelight}"/>
        <Setter Property="BorderThickness" Value="0"/>
        <Setter Property="Foreground" Value="{StaticResource Foreground}"/>
        <Setter Property="FontFamily" Value="{x:Static Root:Parameters.FontFamily}"/>
        <Setter Property="FontSize" Value="{x:Static Root:Parameters.TextFontSize}"/>
        <Setter Property="FontWeight" Value="Normal"/>
        
        <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
        <Setter Property="Focusable" Value="False"/>

        <Setter Property="SnapsToDevicePixels" Value="True"/>

        <Style.Triggers>

            <Trigger Property="IsEnabled" Value="False">
                <Setter Property="BorderBrush" Value="{StaticResource Disabled}"/>
            </Trigger>

            <Trigger Property="Orientation" Value="Horizontal">

                <Setter Property="MinHeight" Value="4"/>
                <Setter Property="Height" Value="4"/>
                <Setter Property="MaxHeight" Value="8"/>
                
                <Setter Property="Template" Value="{StaticResource HorizontalProgressBarTemplate}"/>

            </Trigger>

            <Trigger Property="Orientation" Value="Vertical">
                
                <Setter Property="MinWidth" Value="4"/>
                <Setter Property="Width" Value="4"/>
                <Setter Property="MaxWidth" Value="8"/>

                <Setter Property="Template" Value="{StaticResource VerticalProgressBarTemplate}"/>

            </Trigger>

        </Style.Triggers>

    </Style>
    
</ResourceDictionary>